'use strict'
const path = require('path')

function resolve(dir) {
  return path.join(__dirname, dir)
}

// const name = '交友网站' // page title

// 端口号
const port = process.env.port || process.env.npm_config_port || 9527
module.exports = {
  // assetsSubDirectory: 'static'
  publicPath: '/',
  outputDir: 'dist',
  assetsDir: 'assets',
  lintOnSave: process.env.NODE_ENV === 'development',
  productionSourceMap: false,
  devServer: {
    // disableHostCheck: true
    port: port,
    // open: true,
    // host: '0.0.0.0',
    overlay: {
      warnings: false,
      errors: true
    },
    proxy: {
      '/admin': {
        target: ' ',
        changeOrigin: true,
        ws: true,
        pathRewrite: {
          '^/admin': ''
        }
      }
    }
  },
  chainWebpack: (config) => {
    config.resolve.alias
      .set('@', resolve('src'))
      .set('api', resolve('src/service/api'))
      .set('util', resolve('src/utils/index'))
    // config.module.rule('images').use('url-loader')
    //     .tap(options => ({
    //         name: './assets/images/[name].[ext]',
    //         quality: 85,
    //         limit: 0,
    //         esModule: false,
    //     }));
    const svgRule = config.module.rule('svg')
    svgRule.uses.clear()
    svgRule
      .rule('svg-sprite-loader')
      .test(/\.svg$/)
      .include.add(resolve('src/assets/svg-icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
  }
}
